package com.lvmama.service.dw.impl;

import java.util.List;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lvmama.common.result.CodeMessage;
import com.lvmama.common.result.Result;
import com.lvmama.dao.dw.priceStock.StockAndPriceSearchDao;
import com.lvmama.pojo.entity.dw.priceStock.StockAndPriceSearch;
import com.lvmama.service.dw.StockAndPriceSearchService;

/**
 * @Author:xuzhongwei
 * @Description:
 * @Date：2018/08/06
 */
@Slf4j
@Service("stockAndPriceSearchService")
public class StockAndPriceSearchServiceImpl implements StockAndPriceSearchService {

    @Autowired
    private StockAndPriceSearchDao stockAndPriceSearchDao;
    
	@Override
	public Result<List<StockAndPriceSearch>> selectCategoryList() {
		log.info("selectCategoryList start" );
		try {
			List<StockAndPriceSearch> resultList = stockAndPriceSearchDao.selectCategoryList();
			log.info("selectCategoryList  result:{}", ToStringBuilder.reflectionToString(resultList, ToStringStyle.DEFAULT_STYLE));
			return Result.success(resultList);			
		} catch (Exception e) {
			log.error("selectCategoryList error:" + e.getMessage(), e);
			return Result.error(CodeMessage.SERVER_ERROR);
		}
	}

	@Override
	public Result<List<StockAndPriceSearch>> selectChannelList() {
		log.info("selectChannelList start" );
		try {
			List<StockAndPriceSearch> resultList = stockAndPriceSearchDao.selectChannelList();
			log.info("selectChannelList  result:{}", ToStringBuilder.reflectionToString(resultList, ToStringStyle.DEFAULT_STYLE));
			return Result.success(resultList);	
		} catch (Exception e) {
			log.error("selectChannelList error:" + e.getMessage(), e);
			return Result.error(CodeMessage.SERVER_ERROR);
		}
	}

	@Override
	public Result<List<StockAndPriceSearch>> selectProductList() {
		log.info("selectProductList start" );
		try {
			List<StockAndPriceSearch> resultList = stockAndPriceSearchDao.selectProductList();
			log.info("selectProductList  result:{}", ToStringBuilder.reflectionToString(resultList, ToStringStyle.DEFAULT_STYLE));
			return Result.success(resultList);	
		} catch (Exception e) {
			log.error("selectProductList error:" + e.getMessage(), e);
			return Result.error(CodeMessage.SERVER_ERROR);
		}
	}

	@Override
	public Result<List<StockAndPriceSearch>> selectProductManagerList(String regioname) {
		
		log.info("selectProductManagerList start and param =" + regioname );
		try {
			if (regioname == null || "".equals(regioname)){
				log.error("selectProductManagerList error: 参数为空");
				return Result.error(CodeMessage.BIND_ERROR);
			}else{
				List<StockAndPriceSearch> resultList = stockAndPriceSearchDao.selectProductManagerList(regioname);
				log.info("selectProductManagerList  result:{}", ToStringBuilder.reflectionToString(resultList, ToStringStyle.DEFAULT_STYLE));
				return Result.success(resultList);	
			}
		} catch (Exception e) {
			log.error("selectProductManagerList error:" + e.getMessage(), e);
			return Result.error(CodeMessage.SERVER_ERROR);
		}
	}

	@Override
	public Result<List<StockAndPriceSearch>> selectRegionList() {
		
		log.info("selectRegionList start " );
		try {
			List<StockAndPriceSearch> resultList = stockAndPriceSearchDao.selectRegionList();
			log.info("selectRegionList  result:{}", ToStringBuilder.reflectionToString(resultList, ToStringStyle.DEFAULT_STYLE));
			return Result.success(resultList);
		} catch (Exception e) {
			log.error("selectRegionList error:" + e.getMessage(), e);
			return Result.error(CodeMessage.SERVER_ERROR);
		}
	}

	@Override
	public Result<List<StockAndPriceSearch>> selectSupperNameList() {
		
		log.info("selectSupperNameList start " );
		try {
			List<StockAndPriceSearch> resultList = stockAndPriceSearchDao.selectSupperNameList();
			log.info("selectSupperNameList  result:{}", ToStringBuilder.reflectionToString(resultList, ToStringStyle.DEFAULT_STYLE));
			return Result.success(resultList);
		} catch (Exception e) {
			log.error("selectSupperNameList error:" + e.getMessage(), e);
			return Result.error(CodeMessage.SERVER_ERROR);
		}
	}

	@Override
	public Result<List<StockAndPriceSearch>> selectSupperTypeList() {
		
		log.info("selectSupperTypeList start " );
		try {
			List<StockAndPriceSearch> resultList = stockAndPriceSearchDao.selectSupperTypeList();
			log.info("selectSupperTypeList  result:{}", ToStringBuilder.reflectionToString(resultList, ToStringStyle.DEFAULT_STYLE));
			return Result.success(resultList);
		} catch (Exception e) {
			log.error("selectSupperTypeList error:" + e.getMessage(), e);
			return Result.error(CodeMessage.SERVER_ERROR);
		}
	}
}
